import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'

type State = {
  deep: {
    nested: {
      obj: { count: number }
    }
  }
  // 状态更新方法
  incrementDeepCount: () => void
  decrementDeepCount: () => void
  setDeepCount: (count: number) => void
}

const useDeepStore = create<State>()(
  immer((set) => ({
    // 初始状态
    deep: {
      nested: {
        obj: { count: 0 }
      }
    },
    
    // 使用 Immer 的状态更新方法
    incrementDeepCount: () => 
      set((state) => {
        state.deep.nested.obj.count += 1
      }),
      
    decrementDeepCount: () => 
      set((state) => {
        state.deep.nested.obj.count -= 1
      }),
      
    setDeepCount: (count: number) => 
      set((state) => {
        state.deep.nested.obj.count = count
      })
  }))
)

export default useDeepStore